﻿CREATE FUNCTION dbo.f_RevolvingsTotal
(@LoanID int)RETURNS int WITH SCHEMABINDING BEGIN 

DECLARE @Ret int

SELECT @Ret = SUM(ISNULL(NULLIF(Term,0),Ballance*.02))
FROM dbo.v_TradeReferences
WHERE LoanID = @LoanID AND AccType = 'R' AND AccountState = 1

RETURN ISNULL(@Ret,0)

END
